package com.literature.search.user.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import com.literature.search.core.config.swagger.BaseSwaggerConfiguration;
import com.literature.search.core.enums.CodeEnum;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMethod;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.builders.ResponseMessageBuilder;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ResponseMessage;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Configuration
@EnableKnife4j
public class UserSwaggerConfiguration extends BaseSwaggerConfiguration {
    @Bean(value = "UserApi")
    public Docket EsApi() {
        List<ResponseMessage> responseMessageList = new ArrayList<>();
        Arrays.stream(CodeEnum.values()).forEach(codeEnum -> {
            responseMessageList.add(
                    new ResponseMessageBuilder().code(codeEnum.getCode()).message(codeEnum.getMsg()).responseModel(
                            new ModelRef(codeEnum.getMsg())).build());
        });
        Docket docket=new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        //.title("swagger-bootstrap-ui-demo RESTful APIs")
                        .description("前端小哥哥们加油！！！！")
                        .termsOfServiceUrl("没有链接....")
                        .contact("1601709391@qq.com")
                        .version("1.0")
                        .build())
                //分组名称
                .groupName("User")
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("com.literature.search.user.controller"))
                .paths(PathSelectors.any())
                .build()
                .globalOperationParameters(getGlobalOperationParameters())
                .globalOperationParameters(getGlobalOperationParameters())
                .globalResponseMessage(RequestMethod.GET,responseMessageList)
                .globalResponseMessage(RequestMethod.POST,responseMessageList)
                .globalResponseMessage(RequestMethod.PUT,responseMessageList)
                .globalResponseMessage(RequestMethod.DELETE,responseMessageList);
        return docket;
    }

}
